package com.sxjh.mapper;

import com.sxjh.entity.bo.*;
import com.sxjh.entity.param.*;
import com.sxjh.entity.result.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public interface FinanceMapper {

  List<MethylAlcoholListResult> list(MethylAlcoholListParam param);

  List<MethylAlcoholListResult> list2(Finance6ListParam param);

  List<Finance9List3Bo> list3(FinanceList3Param param);

  List<FinanceList4Result> list4(FinanceList3Param param);

  List<Finance9List7Bo> list5(FinanceList3Param param);

  List<Finance9List9Result> list6(FinanceList3Param param);

  List<Finance9ListDtResult> list6Dt(FinanceList3Param param);

  List<Finance9ListDtResult> list8Dt(FinanceList3Param param);

  List<Finance3CbBo> list7(Finance3CbParam param);

  List<Finance3CbBo> list8(Finance3CbParam param);

  List<Finance4ListResult> list9(Finance4ListParam param);

  List<Finance5ListResult> list10(Finance5ListParam param);

  List<Finance4KhXsResult> list11(Finance4ListParam param);

  List<Finance4KhXsResult> list12(Finance4ListParam param);

  List<Finance4KhXsResult> list13(Finance4ListParam param);

  List<Finance4KhXsResult> list14(Finance4ListParam param);

  List<Finance4KhMxResult> list15(Finance4ListParam param);

  List<Finance4KhMxResult> list16(Finance4ListParam param);

  List<Finance4KhKpResult> list17(Finance4ListParam param);

  List<Finance4KhKpResult> list18(Finance4ListParam param);

  List<Finance6ListResult> list19(Finance6ListParam param);

  List<Finance7ListResult> list20(Finance7ListParam param);

  List<Finance8Bo> list21(Finance8Param param);

  List<Finance8List2Bo> list22(Finance8Param param);

  List<Finance9ListResult> list23(FinanceList3Param param);

  List<Finance9ListDtResult> list23Dt(FinanceList3Param param);

  List<Finance8List3Bo> list24(Finance8List3Param param);

  List<Finance8List4Bo> list25(Finance8List4Param param);

  List<Finance7ListBo> list26(Finance7ListParam param);

  /**
   * 余额报表
   * -- 时间最早的那条数据，变动前就是上月余额
   * -- 时间最晚的那条数据，变动后就是余额
   * -- type=1 变动金额的和 的绝对值就是本月货款
   * -- type=3 变动金额的和 的绝对值就是现汇汇款
   * -- type=4 变动金额的和 的绝对值就是承兑汇款
   * -- type=5 变动金额的和 的绝对值就是转账
   * -- 电子汇款不需要做
   */
  List<Finance10Bo> list27(Finance10Param param);
  List<Finance4KhMxResult> list28(Finance4ListParam param);

  List<Integer> getTruckingIdList(Finance7FillParam param);

    Finance10Bo checkBalance(Finance10Param param1);

    List<Finance3HgylcgrbbBo> list29(Finance10Param param1);
    List<Finance3HgyljcyhzbBo> list30(Finance10Param param1);
  @Select("SELECT id materialId,name materialName from materials where category_id =10")
  List<Finance3HgcgwlResult> list31();

  /**
   * 财务报表
   * @param param
   * @return
   */
  List<FinanceResult> getFinanceReport(FinanceParam param);
  @Insert("INSERT INTO monthly_balance(supplier_id,company_name,balance_date,opening_balance,ending_balance,payment,billing,created_time) values(#{supplierId},#{companyName},#{balanceDate},#{openingBalance},#{endingBalance},#{payment},#{billing},#{createdTime})")
  int  getInsertSupplier(MonthlyBalanceBo supplierBo);

  MonthlyBalanceBo getTb1Tb2(yueParam yueParam);
  @Select("select * from monthly_balance where balance_date='2021-09'")
  List<MonthlyBalanceBo> getMonthlyBalanceBos();
  @Select("\tSELECT  sum(ws.recorded_money) billing from suppliers ss LEFT JOIN water_bills ws on ws.company_code = ss.`code` \n" +
          "where ss.id=#{supplierId} and recorded_date>='2021-09-26 00:00:00' and recorded_date <='2021-09-30 23:59:59' ")
  MonthlyBalanceBo getBill(Integer supplierId);
  @Select("SELECT  sum(ws.recorded_money) billing from suppliers ss LEFT JOIN water_bills ws on ws.company_code = ss.`code` where ss.id=#{supplierId} and recorded_date>=#{startDate} and recorded_date <=#{endDate} ")
  MonthlyBalanceBo getBilling(@Param("supplierId") Integer supplierId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
  @Select("SELECT customer_credit from suppliers where id =#{supplierId} ")
  BigDecimal getCustomerCredit(@Param("supplierId") Integer supplierId);
  @Select(" SELECT tb4.after_change from\n" +
          " (SELECT id,company_name\tfrom suppliers where type =1 and id=#{supplierId}) tb1 \n" +
          " left join\n" +
          " (select tb3.after_change,tb3.supplier_id from (select  MAX(id) id,supplier_id from capital_change  where created_at<='2021-08-25 23:59:59' GROUP BY supplier_id order BY supplier_id,created_at desc) tb2 LEFT JOIN capital_change tb3 on tb2.id = tb3.id AND tb2.supplier_id = tb3.supplier_id) tb4 on tb1.id=tb4.supplier_id ")
  BigDecimal getAfterChange(@Param("supplierId") Integer supplierId);
  List<MonthlyBalanceBo> getTb(yueParam yueParam);
  List<MonthlyBalanceBo> getMonthlyBalanceBo(yueParam yueParam);
  List<MonthlyBalanceBo> getMonthlyBalanceBo1(yueParam yueParam);
  List<MonthlyBalanceBo> getMonthlyBalanceResults(yueParam yueParam);
}
